#if !defined(__APP_BUFFER_H)
#define __APP_BUFFER_H

#include "stdlib.h"
#include "log/log.h"
#include "string.h"
#include "pthread.h"

#define MAX_MSG_SIZE (256 - 1)

// 小缓冲区
typedef struct
{
    // 用于存储数据的指针首地址
    unsigned char *ptr;
    int total_size;
    int len;
} SubBuffer;

// 大缓冲区
typedef struct
{
    SubBuffer *sub_buffer[2];
    int read_index;
    int write_index;
    // 读写锁
    pthread_mutex_t read_lock;
    pthread_mutex_t write_lock;
} Buffer;

Buffer *app_buffer_init(int total_size);

void app_buffer_deinit(Buffer *buffer);

int app_buffer_write(Buffer *buffer, char *data, int data_len);

int app_buffer_read(Buffer *buffer, char *data_buf, int data_buf_len);

#endif // __APP_BUFFER_H
